package com.njtoyo.taxi.admin.rest.wrapper.marketing.coupon;

import cn.hutool.core.date.DateTime;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njtoyo.taxi.admin.mapper.master.entity.Coupon;
import com.njtoyo.taxi.admin.mapper.master.enums.CouponCategory;
import com.njtoyo.taxi.admin.mapper.master.enums.CouponDiscountType;
import com.njtoyo.taxi.admin.mapper.master.enums.CouponUsageCondition;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Objects;

@Data
@ApiModel("指定乘客的活跃优惠券列表")
public class CouponHotQueryWrapper extends Page<Coupon> {

    @ApiModelProperty(value = "是否使用")
    private Boolean hadUsed;

    @ApiModelProperty(value = "0:mix,1:reduction,2:fullreduction,3:discount")
    private CouponCategory category;

    public Integer getHadUsed() {
        if (Objects.isNull(hadUsed)) {
            return null;
        }

        return hadUsed ? 1 : 0;
    }

    @ApiModelProperty(value = "优惠券类型：0:reduction(减免),1:discount(折扣)")
    private CouponDiscountType discountType;

    @ApiModelProperty(value = "使用条件(0:FULL，1:MAX)")
    private CouponUsageCondition usageCondition;

    @ApiModelProperty("发放开始时间，格式：yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime grantedStart;

    @ApiModelProperty(value = "发放结束时间，格式：yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime grantedEnd;

    @ApiModelProperty("使用开始时间，格式：yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime usedStart;

    @ApiModelProperty(value = "使用结束时间，格式：yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private DateTime usedEnd;

    public CouponHotQueryWrapper(Long current, Long size) {
        super(Objects.isNull(current) ? 1 : current, Objects.isNull(size) ? 15 : size);
    }

    public Long getGrantedStart() {
        return Objects.nonNull(grantedStart) ? grantedStart.getTime() / 1000 : null;
    }

    public Long getGrantedEnd() {
        return Objects.nonNull(grantedEnd) ? grantedEnd.getTime() / 1000 : null;
    }

    public Long getUsedStart() {
        return Objects.nonNull(usedStart) ? usedStart.getTime() / 1000 : null;
    }

    public Long getUsedEnd() {
        return Objects.nonNull(usedEnd) ? usedEnd.getTime() / 1000 : null;
    }
}